package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wolfcode.crm.domain.Gift;
import cn.wolfcode.crm.query.GiftQueryObject;
import cn.wolfcode.crm.service.IGiftService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;

/**
 * @author mist
 */
@Controller
@RequestMapping("gift")
public class GiftController {
    @Autowired
    private IGiftService giftService;
    
    @RequiresPermissions("gift:index")
    @PermissionName("礼品首页")
    @RequestMapping("")
    public String index(){
        return "gift/list";
    }

  @RequiresPermissions("gift:list")
    @PermissionName("礼品列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(GiftQueryObject qo){
        return giftService.query(qo);
    }
    
    @RequiresPermissions("gift:save")
    @PermissionName("礼品保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Gift entity){
    	JsonResult result = new JsonResult();
    	try {
    		giftService.save(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("保存失败" + e.getMessage());
		}
        return result;
    }
    
    @RequiresPermissions("gift:update")
    @PermissionName("礼品编辑")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Gift entity){
    	JsonResult result = new JsonResult();
    	try {
    		giftService.update(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("更新失败" + e.getMessage());
		}
        return result;
    }
    
    @RequiresPermissions("gift:delete")
    @PermissionName("礼品删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
    	JsonResult result = new JsonResult();
    	try {
    		giftService.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("删除失败" + e.getMessage());
		}
        return result;
    }
}
